package com.example.demoeureka.api.controller;

import com.example.demoeureka.config.RibbonConfig;
import com.example.demoeureka.service.RibbonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer")
public class consumerController {

    private final Logger logger = LoggerFactory.getLogger(consumerController.class);

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private RibbonService ribbonService;

    @Autowired
    private LoadBalancerClient loadBalancerClient;

    /**
     * @return 使用ribbon来远程调用
     */
    @GetMapping("/loada")
    public void hello() {
        ResponseEntity<String> forEntity =
                restTemplate.getForEntity("HTTP://eureka-Provider/provier/hello/",
                        String.class);
        logger.info("{}", String.valueOf(forEntity));
    }

    /**
     * 使用feign来远程调用
     */
    @GetMapping("/load")
    public void twohello(){
        String hello = ribbonService.getHello();
        logger.info("{}",hello);
    }



}
